1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
| apply plugin: 'com.android.application'
def debugIcon = "@mipmap/ic_launcher" def betaIcon = "@mipmap/ic_launcher" def prodIcon = "@mipmap/ic_launcher"
def keystorePropertiesFile = rootProject.file("keystore.properties")
def jksFile = rootProject.file("markzl.jks")
def keystoreProperties = new Properties() keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) android { compileSdkVersion rootProject.compileSdkVersion defaultConfig { applicationId "com.markzl.android.gradlesetting" minSdkVersion rootProject.minSdkVersion targetSdkVersion rootProject.targetSdkVersion versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" }
signingConfigs { release { storeFile jksFile storePassword keystoreProperties.getProperty("storePassword") keyAlias keystoreProperties.getProperty("keyAlias") keyPassword keystoreProperties.getProperty("keyPassword")
} } buildTypes { release { signingConfig signingConfigs.release buildConfigField("String", "URL_HOST", "\"正式环境地址\"") minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } debug { buildConfigField("String", "URL_HOST", "\"测试环境地址\"") } } flavorDimensions 'default' productFlavors { dev { dimension = 'default' applicationIdSuffix = '.dev' resValue("string", "app_title", "应用名_测试版") resValue("string", "baidu_api_key", "测试版key") manifestPlaceholders = [app_icon: debugIcon] } beta { dimension = 'default' applicationIdSuffix = '.beta' resValue("string", "app_title", "应用名_线上测试版") resValue("string", "baidu_api_key", "线上测试版key") manifestPlaceholders = [app_icon: betaIcon] } prod { dimension = 'default' resValue("string", "app_title", "应用名_线上测试版") resValue("string", "baidu_api_key", "正式版key") manifestPlaceholders = [app_icon: prodIcon] } }
android.variantFilter { variant -> def flavors = variant.getFlavors() if (!flavors.isEmpty()) { def flavorName = flavors.get(0).name def buildTypeName = variant.buildType.name def ignoreVariant = true
switch (buildTypeName) { case "release": switch (flavorName) { case "prod": case "beta": ignoreVariant = false break } break case "debug": switch (flavorName) { case "dev": ignoreVariant = false break } break } variant.setIgnore(ignoreVariant) } } android.applicationVariants.all { variant -> variant.outputs.all { output -> def flavorName = variant.getFlavorName() def buildType = variant.buildType.getName() def versionCode = defaultConfig.versionCode outputFileName = "应用名-${flavorName}-${buildType}.${versionCode}.apk" } } }
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.appcompat:appcompat:$appCompatVersion" implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation "androidx.cardview:cardview:$cardVersion" implementation "com.google.android.material:material:$materialVersion" implementation "androidx.recyclerview:recyclerview:$recyclerViewVersion" implementation "androidx.annotation:annotation:$androidXAnnotations" implementation "com.jakewharton.timber:timber:$timberVersion"
testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
def getGitVersion() { def cmd = "git describe --tag" try { def proc = cmd.execute() return proc.text.trim() } catch (IOException e) { return "please update version name manually" } }
def releaseTime() { return new Date().format("yyyyMMdd_hhmm") }
|